package com.test.controller;


import com.test.entity.StuAllInfoDto;
import com.test.service.CompOperatService;
import com.test.service.StuOperatService;
import com.test.service.TeaOperatService;
import com.test.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("/compOperat")
public class CompOperatController extends BaseController{

    @Autowired
    private CompOperatService compOperatService;

    @Autowired
    private StuOperatService stuOperatService;

    //查看所有学生信息
    @RequestMapping("/selectMyAttentStu")
    @ResponseBody
    public Result selectMyAttentStu(HttpSession session){
        String acount = session.getAttribute("comp_acount").toString();
        Result result = genSuccessResult();
        try {
            List<StuAllInfoDto> stuList = compOperatService.selectMyAttentStu(acount);
            for(int i = 0;i<stuList.size();i++){
                String pidcard = stuList.get(i).getStu_idcard();
                String sixidcard = pidcard.substring(0,12);
                String overidcard = sixidcard+"******";
                stuList.get(i).setStu_idcard(overidcard);
            }
            result .setData(stuList);
        }  catch (Exception e) {
        result = exceptionHandler.handleException(e);
    }
        return result;
    }




    //企业查看网申自己的企业
    @RequestMapping("/selectCompAttentStu")
    @ResponseBody
    public Result selectCompAttentStu(HttpSession session){
        Result result = genSuccessResult();
        String acount = session.getAttribute("comp_acount").toString();
        try {
            List<StuAllInfoDto> stuList = compOperatService.selectCompAttentStu(acount);
            result .setData(stuList);
        }  catch (Exception e) {
            result = exceptionHandler.handleException(e);
        }
        return result;
    }


    //企业查看网申自己的企业
    @RequestMapping("/selectStuOnline")
    @ResponseBody
    public Result selectStuOnline(HttpSession session){
        Result result = genSuccessResult();
        String acount = session.getAttribute("comp_acount").toString();
        try {
            List<StuAllInfoDto> stuList = compOperatService.selectStuOnline(acount);
            result .setData(stuList);
        }  catch (Exception e) {
            result = exceptionHandler.handleException(e);
        }
        return result;
    }

    //企业同意网申自己的企业
    @RequestMapping("/agreeOnlineApplication")
    @ResponseBody
    public String  agreeOnlineApplication(HttpSession session,String stu_acount,String wangshenjob){
        String acount = session.getAttribute("comp_acount").toString();
         int  result = compOperatService.agreeOnlineApplication(acount,stu_acount,wangshenjob);
         if(result>0){
             return "同意成功";
         }else{
             return "同意失败";
         }

    }

    //企业查看网申自己的企业
    @RequestMapping("/disOnlineApplication")
    @ResponseBody
    public String  disOnlineApplication(HttpSession session,String stu_acount,String wangshenjob){
        String arr[] =  stu_acount.split(",");
        String stuAcount = arr[0];
        String acount = session.getAttribute("comp_acount").toString();
        int  result = compOperatService.disOnlineApplication(acount,stuAcount,wangshenjob);
        if(result>0){
            return "拒绝成功";
        }else{
            return "拒绝失败";
        }

    }


    //企业像学生发送笔试预约
    @RequestMapping("/compyuyuebishi")
    @ResponseBody
    public String  compyuyuebishi(HttpSession session,String stu_acount,String wangshenjob){

        String acount = session.getAttribute("comp_acount").toString();
        int  result = compOperatService.compyuyuebishi(acount,stu_acount,wangshenjob);
        if(result>0){
            return "预约成功";
        }else{
            return "预约失败";
        }

    }

    //企业像学生发送面试预约
    @RequestMapping("/compyuyuemianshi")
    @ResponseBody
    public String  compyuyuemianshi(HttpSession session,String stu_acount,String wangshenjob){

        String acount = session.getAttribute("comp_acount").toString();
        int  result = compOperatService.compyuyuemianshi(acount,stu_acount,wangshenjob);
        if(result>0){
            return "预约成功";
        }else{
            return "预约失败";
        }

    }


    //企业像学生发送offer
    @RequestMapping("/sendOffer")
    @ResponseBody
    public String  sendOffer(HttpSession session,String stu_acount,String wangshenjob){

        String acount = session.getAttribute("comp_acount").toString();
        int  result = compOperatService.sendOffer(acount,stu_acount,wangshenjob);
        if(result>0){
            return "预约成功";
        }else{
            return "预约失败";
        }

    }


    //企业查看网申自己的企业
    @RequestMapping("/rebackOnlineApplication")
    @ResponseBody
    public String  rebackOnlineApplication(HttpSession session,String stu_acount,String wangshenjob){
        String arr[] =  stu_acount.split(",");
        String stuAcount = arr[0];
        String acount = session.getAttribute("comp_acount").toString();
        int  result = compOperatService.rebackOnlineApplication(acount,stuAcount,wangshenjob);
        if(result>0){
            return "撤销成功";
        }else{
            return "撤销失败";
        }

    }

    //企业查看学生详情
    @RequestMapping("/selectCountyStuInfo")
    @ResponseBody
    public StuAllInfoDto selectCountyStuInfo(String stu_acount){
        StuAllInfoDto stuAllInfoDto = stuOperatService.selectStuByAcount(stu_acount);
        String province = null;
        if(stuAllInfoDto.getStu_province()!=null&&!"".equals(stuAllInfoDto.getStu_province())){
            province = stuAllInfoDto.getStu_province();
        }
        String city = null;
        if(stuAllInfoDto.getStu_city()!=null&&!"".equals(stuAllInfoDto.getStu_city())){
            city = stuAllInfoDto.getStu_city();
        }
        String county = null;
        if(stuAllInfoDto.getStu_county()!=null&&!"".equals(stuAllInfoDto.getStu_county())){
            county = stuAllInfoDto.getStu_county();
        }
        String address = null;
        if(stuAllInfoDto.getStu_address()!=null&&!"".equals(stuAllInfoDto.getStu_address())){
            address = stuAllInfoDto.getStu_address();
        }

        String addresStr = province+city+county+address;
        stuAllInfoDto.setStu_address(addresStr);
        String fromProvince = null;
        if(stuAllInfoDto.getStu_fromprovince()!=null&&!"".equals(stuAllInfoDto.getStu_fromprovince())){
            fromProvince = stuAllInfoDto.getStu_fromprovince();
        }
        String fromCity = null;
        if(stuAllInfoDto.getStu_fromcity()!=null&&!"".equals(stuAllInfoDto.getStu_fromcity())){
            fromCity = stuAllInfoDto.getStu_fromcity();
        }

        String fromAddressStr = fromProvince+fromCity;
        stuAllInfoDto.setStu_fromaddress(fromAddressStr);
        if(stuAllInfoDto!=null&&!"".equals(stuAllInfoDto)){
            return stuAllInfoDto;
        }else{
            return null;
        }
    }


}
